
<!DOCTYPE html>
<html>

	<head>
	<title>CAIJL's Blog</title>
	<meta charset="utf-8"/>
	<link rel="stylesheet" href="/font-awesome-4.7.0/css/font-awesome.min.css">

	<link rel="stylesheet" href="/bootstrap-3.3.7/css/bootstrap.min.css">
	<script src="/jquery-2.1.1/jquery.min.js"></script>
	<script src="/bootstrap-3.3.7/js/bootstrap.min.js"></script>

	<link rel="stylesheet" href="/css/bootstrap-slider.min.css">
	<script src="/js/bootstrap-slider.min.js"></script>
	
	<link rel="stylesheet" href="/css/main.css">
	<script src="/js/main.js"></script>
	
	<link rel="stylesheet" href="/css/cursor.css">
	<script src="/js/cursor.js"></script>
	
	
	<link rel="stylesheet" href="/css/code.css">
	<!--link rel="stylesheet" href="/css/markdown.css"-->
	
	<link rel="stylesheet" href="/css/head.css">

	<script src="/js/window.js"></script>
	<script src='//unpkg.com/valine/dist/Valine.min.js'></script>
	</head>
<body>

	<link rel="stylesheet" href="/katex/katex.min.css" crossorigin="anonymous">
	<script src="/katex/katex.min.js" crossorigin="anonymous"></script>
	<script src="/katex/contrib/mathtex-script-type.min.js" defer></script>
	<script defer src="/katex/contrib/auto-render.min.js"crossorigin="anonymous"
	    onload="renderMathInElement(document.body);"></script>
	<script>document.addEventListener("DOMContentLoaded", function() {renderMathInElement(document.body,{"delimiters":[{left: "$", right: "$", display: false}]});});</script>
	<nav class="navbar navbar-default header card" role="navigation" style="width: 100%;">
	<div class="container-fluid"> 
	<div class="navbar-header">
		<button type="button" class="navbar-toggle" data-toggle="collapse"
				data-target="#example-navbar-collapse">
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
		</button>
		<a class="navbar-brand" href="/"><span><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="bold">C</mi><mi mathvariant="bold">A</mi><mi mathvariant="bold">I</mi><mi mathvariant="bold">J</mi><msup><mi mathvariant="bold">L</mi><mo mathvariant="bold" lspace="0em" rspace="0em">′</mo></msup><mi mathvariant="bold">s</mi><mi mathvariant="bold">B</mi><mi mathvariant="bold">L</mi><mi mathvariant="bold">O</mi><mi mathvariant="bold">G</mi></mrow><annotation encoding="application/x-tex">\mathbf{CAIJL'sBLOG}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height: 0.751892em; vertical-align: 0em;"></span><span class="mord"><span class="mord mathbf">C</span><span class="mord mathbf">A</span><span class="mord mathbf">I</span><span class="mord mathbf">J</span><span class="mord"><span class="mord mathbf">L</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height: 0.751892em;"><span class="" style="top: -3.063em; margin-right: 0.05em;"><span class="pstrut" style="height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathbf mtight">′</span></span></span></span></span></span></span></span></span><span class="mord mathbf">s</span><span class="mord mathbf">B</span><span class="mord mathbf">L</span><span class="mord mathbf">O</span><span class="mord mathbf">G</span></span></span></span></span></span></a>
	</div>
	<div class="collapse navbar-collapse" id="example-navbar-collapse">
		<ul class="nav navbar-nav" style="background-color:#fcfcfc">
			<li><a href="/"><i class="menu-item-icon fa fa-fw fa-home"></i>首页</a></li>
			<li><a href="/archives/"><i class="menu-item-icon fa fa-fw fa-archive"></i>文章</a></li>
			<li><a href="/tags/"><i class="menu-item-icon fa fa-fw fa-tags"></i>标签</a></li>
			<li><a href="/settings/"><i class="menu-item-icon fa fa-fw fa-cogs"></i>设置</a></li>
			<!--li><a href="/about/"><i class="menu-item-icon fa fa-fw fa-user"></i>关于</a></li-->
			<li><a href="/games/"><i class="menu-item-icon fa fa-fw fa-gamepad"></i>其它</a></li>
			

		</ul>
	</div>
	</div>
	</nav>
<div class="container">
	<div style="height: 60px;"></div>
	<div class="row" >
		<div class="col-md-8">
			<div class="panel panel-default card" style="padding: 10px;position: relative;">
                <img src='/img/bg/5.png' style="width:100%"/>
				<span style="position: absolute;left:15px;bottom:15px;width:90%;"><font class="view-text" style="color:#fcfcfc;font-size:25px">题解 P7468 【[NOI Online 2021 提高组] 愤怒的小 N】</font><br><a href="/tags/2021/" class="tag"><span  style="background-color: rgb(52, 152, 219);">2021</span></a>&nbsp;<a href="/tags/生成函数/" class="tag"><span  style="background-color: rgb(231, 76, 60);">生成函数</span></a>&nbsp;<a href="/tags/题解/" class="tag"><span  style="background-color: rgb(82, 196, 26);">题解</span></a></span>
			</div>
			<div class="panel panel-default card" style="padding: 10px;" id="main">
                <h2 id="_1">题意</h2>
<p><input value="在洛谷上查看" type="button" onclick="creat('https://www.luogu.com.cn/problem/P7468')" class="btn btn-link"/></p>
<ol>
<li>初始有一个字符串 <script type="math/tex">s</script> 为 <script type="math/tex">\texttt{a}</script>。</li>
<li>把 <script type="math/tex">\texttt a</script> 换成 <script type="math/tex">\texttt b</script> , <script type="math/tex">\texttt b</script> 换成 <script type="math/tex">\texttt a</script> 得到 <script type="math/tex">t</script> 拼接在 <script type="math/tex">s</script> 后。</li>
<li>重复 <script type="math/tex">2</script>。</li>
</ol>
<p>得到一个无限长的字符串 <script type="math/tex">s=\texttt{abbabaabbaababba}\ldots</script>，问前 <script type="math/tex">n</script> 位（从 <script type="math/tex">0</script> 开始标号）为 <script type="math/tex">\texttt{b}</script> 的位置的 <script type="math/tex">f(i)</script> 之和。</p>
<p>
<script type="math/tex">\log_2n\le 5\times 10^5,k\le 500</script>
</p>
<h2 id="_2">题解</h2>
<p>考虑一些数的幂和的生成函数：
<script type="math/tex; mode=display">\boxed{\color{orange}F(\mathcal S;x)=\sum_{u\in \mathcal S}e^{ux}}</script>
这个东西有什么用吗？其实是有的，不难发现：
<script type="math/tex; mode=display">k![x^k]F(\mathcal S;x)=\sum_{u\in\mathcal S}u^k</script>
之所以用 <script type="math/tex">\mathbf{EGF}</script> 是因为可以对 <script type="math/tex">\mathcal S</script> 进行方便的全局加。</p>
<p>来看问题，设前 <script type="math/tex">2^n</script> 中为 <script type="math/tex">\texttt{a}</script> 的位置集合为 <script type="math/tex">\mathcal A_n</script>，前 <script type="math/tex">2^n</script> 中为 <script type="math/tex">\texttt{b}</script> 的位置的集合为 <script type="math/tex">\mathcal B_n</script>。为了表述的方便，记 <script type="math/tex">A_n(x)=F(\mathcal A_n;x),B_n(x)=F(\mathcal B_n;x)</script>。</p>
<p>那么转移就是：
<script type="math/tex; mode=display">\begin{aligned}\mathcal A_{n+1}=\mathcal A_n+(\mathcal B_n\rightarrow 2^n)\\\mathcal B_{n+1}=\mathcal B_n+(\mathcal A_n\rightarrow 2^n)\end{aligned}</script>
式中的 <script type="math/tex">\rightarrow c</script> 表示集合内所有的元素加 <script type="math/tex">c</script>。那么考虑 <script type="math/tex">\mathcal S\Longrightarrow (\mathcal S\rightarrow c)</script> 对应的 <script type="math/tex">\bf GF</script> 的变化。
<script type="math/tex; mode=display">F(\mathcal S\rightarrow c;x)=\sum_{u\in\mathcal S}e^{(u+c)x}=e^{cx}\sum_{u\in\mathcal S}e^{ux}=e^cF(\mathcal S;x)</script>
于是就可以用代数语言描述递推式了：
<script type="math/tex; mode=display">\begin{aligned}
{A_{n+1}(x)=A_n(x)+e^{2^nx}B_n(x)}\quad(1)\\
{B_{n+1}(x)=B_n(x)+e^{2^nx}A_n(x)}\quad(2)
\end{aligned}</script>
边界为 <script type="math/tex">A_0(x)=1,B_0(x)=0</script>
</p>
<p>这个东西有什么用吗？现在我们已经能求出所有 <script type="math/tex">2^n</script> 时的答案了，那么怎么求 <script type="math/tex">n</script> 呢？</p>
<p>考虑每局第一位不同的位置 <script type="math/tex">w</script> ，前面的值为 <script type="math/tex">c</script>，就可以计算了。注意前面的奇数/偶数的个数来判断是 <script type="math/tex">A_w(x)</script> 还是 <script type="math/tex">B_w(x)</script>。</p>
<p>不过这样还是可怜的 <script type="math/tex">\mathcal O(k^2\log n )</script>，与暴力数位 <script type="math/tex">\rm dp</script> 同分</p>
<p>『能不能给力一点啊！！！』</p>
<p>其实是可以的 ，<script type="math/tex">(1)-(2)</script> 得到：
<script type="math/tex; mode=display">A_{n+1}(x)-B_{n+1}(x)=(1-e^{2^nx})\left[A_n(x)-B_n(x)\right]</script>
众所周知 <script type="math/tex">1-e^{2^nx}</script> 的常数项为 <script type="math/tex">0</script> 也就意味着若 <script type="math/tex">A_n(x)-B_n(x)</script> 的最低次项为 <script type="math/tex">a</script> 次，<script type="math/tex">A_{n+1}(x)-B_{n+1}(x)</script> 的最低次为 <script type="math/tex">c+1</script>。归纳一下就是 <script type="math/tex">A_{n}(x)-B_n(x)\equiv 0 \bmod{x^n}</script>
</p>
<p>这个又有什么用呢？因为我们之关注生成函数 <script type="math/tex">\bmod {x^k}</script> 后的结果，因此对于 <script type="math/tex">n\ge k</script> 的部分，认为 <script type="math/tex">A_n(x)\equiv B_n(x) \bmod{x^k}</script>。</p>
<p>这是一个非常强的结论，意味着如果能求出 <script type="math/tex">A_n(x)+B_n(x)</script>，除以 <script type="math/tex">2</script> 就是我们想要的结果。 <script type="math/tex">A_n(x)+B_n(x)</script> 是不难得到的，因为 <script type="math/tex">\mathcal A_n\cup\mathcal B_n=\{0,1,2,\ldots,2^{n}-1\}</script>：
<script type="math/tex; mode=display">A_n(x)+B_n(x)=\sum_{i=0}^{2^n-1}e^{ix}</script>
这个还是没有用。考虑已经处理了 <script type="math/tex">w\le k</script> 的部分，那么剩下的部分应该是连续的一段。欢句话说，除了已经处理的部分外，剩下部分的生成函数满足：
<script type="math/tex; mode=display">A(x)\equiv B(x)\equiv \frac12\sum_{i< R}e^{ix}=\frac{e^{Rx}-1}{e^x-1}\bmod {x^k}</script>
式子中的 <script type="math/tex">R</script> 指的是最大的没有处理的值。</p>
<p>那么现在就是稳的 <script type="math/tex">\mathcal O(\log_2n+k^3)</script> 了！！</p>
<h2 id="_3">代码</h2>
<p>都到这一步了代码应该十分好写...</p>
<p>照着式子打就好了。</p>
<p>为了可读性可能有点慢</p>
<div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="  1 "></span><span class="cp">#include</span><span class="cpf">&lt;bits/stdc++.h&gt;</span><span class="cp"></span>
<span class="linenos" data-linenos="  2 "></span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="linenos" data-linenos="  3 "></span><span class="k">template</span><span class="o">&lt;</span><span class="k">const</span> <span class="kt">int</span> <span class="n">mod</span><span class="o">&gt;</span>
<span class="linenos" data-linenos="  4 "></span><span class="k">struct</span> <span class="nc">modint</span><span class="p">{</span>
<span class="linenos" data-linenos="  5 "></span>    <span class="kt">int</span> <span class="n">x</span><span class="p">;</span>
<span class="linenos" data-linenos="  6 "></span>    <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span><span class="p">(</span><span class="kt">int</span> <span class="n">o</span><span class="o">=</span><span class="mi">0</span><span class="p">){</span><span class="n">x</span><span class="o">=</span><span class="n">o</span><span class="o">%</span><span class="n">mod</span><span class="p">;}</span>
<span class="linenos" data-linenos="  7 "></span>    <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="k">operator</span> <span class="o">=</span> <span class="p">(</span><span class="kt">int</span> <span class="n">o</span><span class="p">){</span><span class="k">return</span> <span class="n">x</span><span class="o">=</span><span class="n">o</span><span class="p">,</span><span class="o">*</span><span class="k">this</span><span class="p">;}</span>
<span class="linenos" data-linenos="  8 "></span>    <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="k">operator</span> <span class="o">+=</span><span class="p">(</span><span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="n">o</span><span class="p">){</span><span class="k">return</span> <span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="o">+</span><span class="n">o</span><span class="p">.</span><span class="n">x</span><span class="o">&gt;=</span><span class="n">mod</span><span class="o">?</span><span class="n">x</span><span class="o">+</span><span class="n">o</span><span class="p">.</span><span class="n">x</span><span class="o">-</span><span class="nl">mod</span><span class="p">:</span><span class="n">x</span><span class="o">+</span><span class="n">o</span><span class="p">.</span><span class="n">x</span><span class="p">,</span><span class="o">*</span><span class="k">this</span><span class="p">;}</span>
<span class="linenos" data-linenos="  9 "></span>    <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="k">operator</span> <span class="o">-=</span><span class="p">(</span><span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="n">o</span><span class="p">){</span><span class="k">return</span> <span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="o">-</span><span class="n">o</span><span class="p">.</span><span class="n">x</span><span class="o">&lt;</span><span class="mi">0</span><span class="o">?</span><span class="n">x</span><span class="o">-</span><span class="n">o</span><span class="p">.</span><span class="n">x</span><span class="o">+</span><span class="nl">mod</span><span class="p">:</span><span class="n">x</span><span class="o">-</span><span class="n">o</span><span class="p">.</span><span class="n">x</span><span class="p">,</span><span class="o">*</span><span class="k">this</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 10 "></span>    <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="k">operator</span> <span class="o">*=</span><span class="p">(</span><span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="n">o</span><span class="p">){</span><span class="k">return</span> <span class="n">x</span><span class="o">=</span><span class="mf">1l</span><span class="n">l</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">o</span><span class="p">.</span><span class="n">x</span><span class="o">%</span><span class="n">mod</span><span class="p">,</span><span class="o">*</span><span class="k">this</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 11 "></span>    <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="k">operator</span> <span class="o">^=</span><span class="p">(</span><span class="kt">int</span> <span class="n">b</span><span class="p">){</span>
<span class="linenos" data-linenos=" 12 "></span>        <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="n">a</span><span class="o">=*</span><span class="k">this</span><span class="p">,</span><span class="n">c</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="linenos" data-linenos=" 13 "></span>        <span class="k">for</span><span class="p">(;</span><span class="n">b</span><span class="p">;</span><span class="n">b</span><span class="o">&gt;&gt;=</span><span class="mi">1</span><span class="p">,</span><span class="n">a</span><span class="o">*=</span><span class="n">a</span><span class="p">)</span><span class="k">if</span><span class="p">(</span><span class="n">b</span><span class="o">&amp;</span><span class="mi">1</span><span class="p">)</span><span class="n">c</span><span class="o">*=</span><span class="n">a</span><span class="p">;</span>
<span class="linenos" data-linenos=" 14 "></span>        <span class="k">return</span> <span class="n">x</span><span class="o">=</span><span class="n">c</span><span class="p">.</span><span class="n">x</span><span class="p">,</span><span class="o">*</span><span class="k">this</span><span class="p">;</span>
<span class="linenos" data-linenos=" 15 "></span>    <span class="p">}</span>
<span class="linenos" data-linenos=" 16 "></span>    <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="k">operator</span> <span class="o">/=</span><span class="p">(</span><span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="n">o</span><span class="p">){</span><span class="k">return</span> <span class="o">*</span><span class="k">this</span> <span class="o">*=</span><span class="n">o</span><span class="o">^=</span><span class="n">mod</span><span class="mi">-2</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 17 "></span>    <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="k">operator</span> <span class="o">+=</span><span class="p">(</span><span class="kt">int</span> <span class="n">o</span><span class="p">){</span><span class="k">return</span> <span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="o">+</span><span class="n">o</span><span class="o">&gt;=</span><span class="n">mod</span><span class="o">?</span><span class="n">x</span><span class="o">+</span><span class="n">o</span><span class="o">-</span><span class="nl">mod</span><span class="p">:</span><span class="n">x</span><span class="o">+</span><span class="n">o</span><span class="p">,</span><span class="o">*</span><span class="k">this</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 18 "></span>    <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="k">operator</span> <span class="o">-=</span><span class="p">(</span><span class="kt">int</span> <span class="n">o</span><span class="p">){</span><span class="k">return</span> <span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="o">-</span><span class="n">o</span><span class="o">&lt;</span><span class="mi">0</span><span class="o">?</span><span class="n">x</span><span class="o">-</span><span class="n">o</span><span class="o">+</span><span class="nl">mod</span><span class="p">:</span><span class="n">x</span><span class="o">-</span><span class="n">o</span><span class="p">,</span><span class="o">*</span><span class="k">this</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 19 "></span>    <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="k">operator</span> <span class="o">*=</span><span class="p">(</span><span class="kt">int</span> <span class="n">o</span><span class="p">){</span><span class="k">return</span> <span class="n">x</span><span class="o">=</span><span class="mf">1l</span><span class="n">l</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">o</span><span class="o">%</span><span class="n">mod</span><span class="p">,</span><span class="o">*</span><span class="k">this</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 20 "></span>    <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="k">operator</span> <span class="o">/=</span><span class="p">(</span><span class="kt">int</span> <span class="n">o</span><span class="p">){</span><span class="k">return</span> <span class="o">*</span><span class="k">this</span> <span class="o">*=</span> <span class="p">((</span><span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span><span class="p">(</span><span class="n">o</span><span class="p">))</span><span class="o">^=</span><span class="n">mod</span><span class="mi">-2</span><span class="p">);}</span>
<span class="linenos" data-linenos=" 21 "></span>    <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">I</span><span class="o">&gt;</span><span class="k">friend</span> <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="k">operator</span> <span class="o">+</span><span class="p">(</span><span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="n">a</span><span class="p">,</span><span class="n">I</span> <span class="n">b</span><span class="p">){</span><span class="k">return</span> <span class="n">a</span><span class="o">+=</span><span class="n">b</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 22 "></span>    <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">I</span><span class="o">&gt;</span><span class="k">friend</span> <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="k">operator</span> <span class="o">-</span><span class="p">(</span><span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="n">a</span><span class="p">,</span><span class="n">I</span> <span class="n">b</span><span class="p">){</span><span class="k">return</span> <span class="n">a</span><span class="o">-=</span><span class="n">b</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 23 "></span>    <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">I</span><span class="o">&gt;</span><span class="k">friend</span> <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="k">operator</span> <span class="o">*</span><span class="p">(</span><span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="n">a</span><span class="p">,</span><span class="n">I</span> <span class="n">b</span><span class="p">){</span><span class="k">return</span> <span class="n">a</span><span class="o">*=</span><span class="n">b</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 24 "></span>    <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">I</span><span class="o">&gt;</span><span class="k">friend</span> <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="k">operator</span> <span class="o">/</span><span class="p">(</span><span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="n">a</span><span class="p">,</span><span class="n">I</span> <span class="n">b</span><span class="p">){</span><span class="k">return</span> <span class="n">a</span><span class="o">/=</span><span class="n">b</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 25 "></span>    <span class="k">friend</span> <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="k">operator</span> <span class="o">^</span><span class="p">(</span><span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="n">a</span><span class="p">,</span><span class="kt">int</span> <span class="n">b</span><span class="p">){</span><span class="k">return</span> <span class="n">a</span><span class="o">^=</span><span class="n">b</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 26 "></span>    <span class="k">friend</span> <span class="kt">bool</span> <span class="k">operator</span> <span class="o">==</span><span class="p">(</span><span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="n">a</span><span class="p">,</span><span class="kt">int</span> <span class="n">b</span><span class="p">){</span><span class="k">return</span> <span class="n">a</span><span class="p">.</span><span class="n">x</span><span class="o">==</span><span class="n">b</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 27 "></span>    <span class="k">friend</span> <span class="kt">bool</span> <span class="k">operator</span> <span class="o">!=</span><span class="p">(</span><span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="n">a</span><span class="p">,</span><span class="kt">int</span> <span class="n">b</span><span class="p">){</span><span class="k">return</span> <span class="n">a</span><span class="p">.</span><span class="n">x</span><span class="o">!=</span><span class="n">b</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 28 "></span>    <span class="kt">bool</span> <span class="k">operator</span> <span class="o">!</span> <span class="p">()</span> <span class="p">{</span><span class="k">return</span> <span class="o">!</span><span class="n">x</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 29 "></span>    <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="k">operator</span> <span class="o">-</span> <span class="p">()</span> <span class="p">{</span><span class="k">return</span> <span class="n">x</span><span class="o">?</span><span class="n">mod</span><span class="o">-</span><span class="nl">x</span><span class="p">:</span><span class="mi">0</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 30 "></span>    <span class="n">modint</span><span class="o">&lt;</span><span class="n">mod</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="k">operator</span><span class="o">++</span><span class="p">(</span><span class="kt">int</span><span class="p">){</span><span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="o">+=</span><span class="mi">1</span><span class="p">;}</span>
<span class="linenos" data-linenos=" 31 "></span><span class="p">};</span>
<span class="linenos" data-linenos=" 32 "></span><span class="k">typedef</span> <span class="n">modint</span><span class="o">&lt;</span><span class="mi">1000000007</span><span class="o">&gt;</span> <span class="n">mint</span><span class="p">;</span>
<span class="linenos" data-linenos=" 33 "></span><span class="k">const</span> <span class="kt">int</span> <span class="n">N</span><span class="o">=</span><span class="mf">5e5</span><span class="p">,</span><span class="n">K</span><span class="o">=</span><span class="mi">510</span><span class="p">;</span>
<span class="linenos" data-linenos=" 34 "></span><span class="kt">int</span> <span class="n">n</span><span class="p">,</span><span class="n">k</span><span class="p">,</span><span class="n">a</span><span class="p">[</span><span class="n">K</span><span class="p">];</span>
<span class="linenos" data-linenos=" 35 "></span><span class="kt">char</span> <span class="n">s</span><span class="p">[</span><span class="n">N</span><span class="p">];</span>
<span class="linenos" data-linenos=" 36 "></span><span class="k">struct</span> <span class="nc">poly</span><span class="p">{</span>
<span class="linenos" data-linenos=" 37 "></span>    <span class="n">mint</span> <span class="n">a</span><span class="p">[</span><span class="n">K</span><span class="p">];</span>
<span class="linenos" data-linenos=" 38 "></span>    <span class="n">mint</span><span class="o">&amp;</span><span class="k">operator</span><span class="p">[](</span><span class="k">const</span> <span class="kt">int</span> <span class="n">x</span><span class="p">){</span><span class="k">return</span> <span class="n">a</span><span class="p">[</span><span class="n">x</span><span class="p">];}</span>
<span class="linenos" data-linenos=" 39 "></span>    <span class="n">poly</span><span class="p">(){</span><span class="n">memset</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="k">sizeof</span> <span class="n">a</span><span class="p">);}</span>
<span class="linenos" data-linenos=" 40 "></span>    <span class="n">poly</span> <span class="k">operator</span><span class="o">*</span><span class="p">(</span><span class="n">poly</span> <span class="n">b</span><span class="p">)</span><span class="k">const</span><span class="p">{</span>
<span class="linenos" data-linenos=" 41 "></span>        <span class="n">poly</span> <span class="n">c</span><span class="p">;</span>
<span class="linenos" data-linenos=" 42 "></span>        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">k</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
<span class="linenos" data-linenos=" 43 "></span>            <span class="n">mint</span> <span class="n">sum1</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">sum2</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">sum3</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">sum4</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">sum5</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">sum6</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">sum7</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">sum8</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="linenos" data-linenos=" 44 "></span>            <span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="linenos" data-linenos=" 45 "></span>            <span class="k">for</span><span class="p">(;</span><span class="n">j</span><span class="o">+</span><span class="mi">7</span><span class="o">&lt;=</span><span class="n">i</span><span class="p">;</span><span class="n">j</span><span class="o">+=</span><span class="mi">8</span><span class="p">)</span>
<span class="linenos" data-linenos=" 46 "></span>                <span class="n">sum1</span><span class="o">+=</span><span class="n">a</span><span class="p">[</span><span class="n">j</span>  <span class="p">]</span><span class="o">*</span><span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="n">j</span>  <span class="p">],</span>
<span class="linenos" data-linenos=" 47 "></span>                <span class="n">sum2</span><span class="o">+=</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="n">j</span><span class="mi">-1</span><span class="p">],</span>
<span class="linenos" data-linenos=" 48 "></span>                <span class="n">sum3</span><span class="o">+=</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="o">+</span><span class="mi">2</span><span class="p">]</span><span class="o">*</span><span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="n">j</span><span class="mi">-2</span><span class="p">],</span>
<span class="linenos" data-linenos=" 49 "></span>                <span class="n">sum4</span><span class="o">+=</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="o">+</span><span class="mi">3</span><span class="p">]</span><span class="o">*</span><span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="n">j</span><span class="mi">-3</span><span class="p">],</span>
<span class="linenos" data-linenos=" 50 "></span>                <span class="n">sum5</span><span class="o">+=</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="o">+</span><span class="mi">4</span><span class="p">]</span><span class="o">*</span><span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="n">j</span><span class="mi">-4</span><span class="p">],</span>
<span class="linenos" data-linenos=" 51 "></span>                <span class="n">sum6</span><span class="o">+=</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="o">+</span><span class="mi">5</span><span class="p">]</span><span class="o">*</span><span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="n">j</span><span class="mi">-5</span><span class="p">],</span>
<span class="linenos" data-linenos=" 52 "></span>                <span class="n">sum7</span><span class="o">+=</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="o">+</span><span class="mi">6</span><span class="p">]</span><span class="o">*</span><span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="n">j</span><span class="mi">-6</span><span class="p">],</span>
<span class="linenos" data-linenos=" 53 "></span>                <span class="n">sum8</span><span class="o">+=</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="o">+</span><span class="mi">7</span><span class="p">]</span><span class="o">*</span><span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="n">j</span><span class="mi">-7</span><span class="p">];</span>
<span class="linenos" data-linenos=" 54 "></span>            <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">sum1</span><span class="o">+</span><span class="n">sum2</span><span class="o">+</span><span class="n">sum3</span><span class="o">+</span><span class="n">sum4</span><span class="o">+</span><span class="n">sum5</span><span class="o">+</span><span class="n">sum6</span><span class="o">+</span><span class="n">sum7</span><span class="o">+</span><span class="n">sum8</span><span class="p">;</span>
<span class="linenos" data-linenos=" 55 "></span>            <span class="k">for</span><span class="p">(;</span><span class="n">j</span><span class="o">&lt;=</span><span class="n">i</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="linenos" data-linenos=" 56 "></span>                <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">+=</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">*</span><span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="n">j</span><span class="p">];</span>
<span class="linenos" data-linenos=" 57 "></span>        <span class="p">}</span><span class="k">return</span> <span class="n">c</span><span class="p">;</span>
<span class="linenos" data-linenos=" 58 "></span>    <span class="p">}</span>
<span class="linenos" data-linenos=" 59 "></span>    <span class="n">poly</span> <span class="k">operator</span><span class="o">+</span><span class="p">(</span><span class="n">poly</span> <span class="n">b</span><span class="p">)</span><span class="k">const</span><span class="p">{</span>
<span class="linenos" data-linenos=" 60 "></span>        <span class="n">poly</span> <span class="n">c</span><span class="p">;</span>
<span class="linenos" data-linenos=" 61 "></span>        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">k</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="linenos" data-linenos=" 62 "></span>            <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">+</span><span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="linenos" data-linenos=" 63 "></span>        <span class="k">return</span> <span class="n">c</span><span class="p">;</span>
<span class="linenos" data-linenos=" 64 "></span>    <span class="p">}</span>
<span class="linenos" data-linenos=" 65 "></span>    <span class="n">poly</span> <span class="n">inv</span><span class="p">(){</span>
<span class="linenos" data-linenos=" 66 "></span>        <span class="n">poly</span> <span class="n">c</span><span class="p">;</span><span class="n">c</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="mi">1</span><span class="o">/</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="linenos" data-linenos=" 67 "></span>        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">k</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
<span class="linenos" data-linenos=" 68 "></span>            <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="n">i</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span><span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-=</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="n">j</span><span class="p">]</span><span class="o">*</span><span class="n">c</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="linenos" data-linenos=" 69 "></span>            <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">/=</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="linenos" data-linenos=" 70 "></span>        <span class="p">}</span><span class="k">return</span> <span class="n">c</span><span class="p">;</span>
<span class="linenos" data-linenos=" 71 "></span>    <span class="p">}</span>
<span class="linenos" data-linenos=" 72 "></span><span class="p">};</span>
<span class="linenos" data-linenos=" 73 "></span><span class="n">mint</span> <span class="n">fac</span><span class="p">[</span><span class="n">N</span><span class="p">],</span><span class="n">ifac</span><span class="p">[</span><span class="n">N</span><span class="p">];</span>
<span class="linenos" data-linenos=" 74 "></span><span class="n">poly</span> <span class="n">A</span><span class="p">[</span><span class="n">K</span><span class="p">],</span><span class="n">B</span><span class="p">[</span><span class="n">K</span><span class="p">],</span><span class="n">tmp</span><span class="p">,</span><span class="n">res</span><span class="p">;</span>
<span class="linenos" data-linenos=" 75 "></span><span class="kt">signed</span> <span class="nf">main</span><span class="p">(){</span>
<span class="linenos" data-linenos=" 76 "></span>    <span class="n">fac</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="n">ifac</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="linenos" data-linenos=" 77 "></span>    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">K</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="n">fac</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">fac</span><span class="p">[</span><span class="n">i</span><span class="mi">-1</span><span class="p">]</span><span class="o">*</span><span class="n">i</span><span class="p">,</span><span class="n">ifac</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="mi">1</span><span class="o">/</span><span class="n">fac</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="linenos" data-linenos=" 78 "></span>    <span class="n">scanf</span><span class="p">(</span><span class="s">&quot;%s&quot;</span><span class="p">,</span><span class="n">s</span><span class="p">);</span><span class="n">n</span><span class="o">=</span><span class="n">strlen</span><span class="p">(</span><span class="n">s</span><span class="p">);</span>
<span class="linenos" data-linenos=" 79 "></span>    <span class="n">scanf</span><span class="p">(</span><span class="s">&quot;%d&quot;</span><span class="p">,</span><span class="o">&amp;</span><span class="n">k</span><span class="p">);</span>
<span class="linenos" data-linenos=" 80 "></span>    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">k</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="n">scanf</span><span class="p">(</span><span class="s">&quot;%d&quot;</span><span class="p">,</span><span class="o">&amp;</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="linenos" data-linenos=" 81 "></span>    <span class="n">A</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="linenos" data-linenos=" 82 "></span>    <span class="n">mint</span> <span class="n">pw</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="linenos" data-linenos=" 83 "></span>    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">n</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">n</span><span class="o">&lt;</span><span class="n">k</span><span class="p">;</span><span class="n">n</span><span class="o">++</span><span class="p">,</span><span class="n">pw</span><span class="o">*=</span><span class="mi">2</span><span class="p">){</span>
<span class="linenos" data-linenos=" 84 "></span>        <span class="n">mint</span> <span class="n">tt</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="linenos" data-linenos=" 85 "></span>        <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">k</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">,</span><span class="n">tt</span><span class="o">*=</span><span class="n">pw</span><span class="p">)</span><span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">tt</span><span class="o">*</span><span class="n">ifac</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="linenos" data-linenos=" 86 "></span>        <span class="n">A</span><span class="p">[</span><span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="n">A</span><span class="p">[</span><span class="n">n</span><span class="p">]</span><span class="o">+</span><span class="n">tmp</span><span class="o">*</span><span class="n">B</span><span class="p">[</span><span class="n">n</span><span class="p">];</span>
<span class="linenos" data-linenos=" 87 "></span>        <span class="n">B</span><span class="p">[</span><span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="n">B</span><span class="p">[</span><span class="n">n</span><span class="p">]</span><span class="o">+</span><span class="n">tmp</span><span class="o">*</span><span class="n">A</span><span class="p">[</span><span class="n">n</span><span class="p">];</span>
<span class="linenos" data-linenos=" 88 "></span>    <span class="p">}</span>
<span class="linenos" data-linenos=" 89 "></span>    <span class="n">mint</span> <span class="n">ans</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="linenos" data-linenos=" 90 "></span>    <span class="n">mint</span> <span class="n">R</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">cur</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="kt">bool</span> <span class="n">flag</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="linenos" data-linenos=" 91 "></span>    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
<span class="linenos" data-linenos=" 92 "></span>        <span class="n">cur</span><span class="o">*=</span><span class="mi">2</span><span class="p">;</span><span class="n">R</span><span class="o">*=</span><span class="mi">2</span><span class="p">;</span>
<span class="linenos" data-linenos=" 93 "></span>        <span class="k">if</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">==</span><span class="sc">&#39;1&#39;</span><span class="p">){</span>
<span class="linenos" data-linenos=" 94 "></span>            <span class="kt">int</span> <span class="n">pos</span><span class="o">=</span><span class="n">n</span><span class="o">-</span><span class="n">i</span><span class="mi">-1</span><span class="p">;</span>
<span class="linenos" data-linenos=" 95 "></span>            <span class="k">if</span><span class="p">(</span><span class="n">pos</span><span class="o">&lt;=</span><span class="n">k</span><span class="p">){</span>
<span class="linenos" data-linenos=" 96 "></span>                <span class="n">mint</span> <span class="n">c</span><span class="o">=</span><span class="n">cur</span><span class="o">*</span><span class="p">(</span><span class="n">mint</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">^</span><span class="n">pos</span><span class="p">),</span><span class="n">kk</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="linenos" data-linenos=" 97 "></span>                <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">k</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">,</span><span class="n">kk</span><span class="o">*=</span><span class="n">c</span><span class="p">)</span><span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">kk</span><span class="o">*</span><span class="n">ifac</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="linenos" data-linenos=" 98 "></span>                <span class="k">if</span><span class="p">(</span><span class="n">flag</span><span class="p">)</span><span class="n">res</span><span class="o">=</span><span class="n">A</span><span class="p">[</span><span class="n">pos</span><span class="p">]</span><span class="o">*</span><span class="n">tmp</span><span class="p">;</span>
<span class="linenos" data-linenos=" 99 "></span>                <span class="k">else</span> <span class="n">res</span><span class="o">=</span><span class="n">B</span><span class="p">[</span><span class="n">pos</span><span class="p">]</span><span class="o">*</span><span class="n">tmp</span><span class="p">;</span>
<span class="linenos" data-linenos="100 "></span>                <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">&lt;</span><span class="n">k</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="linenos" data-linenos="101 "></span>                    <span class="n">ans</span><span class="o">+=</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">*</span><span class="n">fac</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">*</span><span class="n">res</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="linenos" data-linenos="102 "></span>            <span class="p">}</span><span class="k">else</span> <span class="n">R</span><span class="o">=</span><span class="n">cur</span><span class="o">+</span><span class="mi">1</span><span class="p">;</span>
<span class="linenos" data-linenos="103 "></span>            <span class="n">cur</span><span class="o">++</span><span class="p">;</span><span class="n">flag</span><span class="o">^=</span><span class="mi">1</span><span class="p">;</span>
<span class="linenos" data-linenos="104 "></span>        <span class="p">}</span>
<span class="linenos" data-linenos="105 "></span>    <span class="p">}</span>
<span class="linenos" data-linenos="106 "></span>    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">k</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="n">tmp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">ifac</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">];</span><span class="c1">//tmp(x)=(e^x-1)/x</span>
<span class="linenos" data-linenos="107 "></span>    <span class="n">pw</span><span class="o">=</span><span class="n">R</span><span class="p">;</span>
<span class="linenos" data-linenos="108 "></span>    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;=</span><span class="n">k</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">,</span><span class="n">pw</span><span class="o">*=</span><span class="n">R</span><span class="p">)</span><span class="n">res</span><span class="p">[</span><span class="n">i</span><span class="mi">-1</span><span class="p">]</span><span class="o">=</span><span class="n">pw</span><span class="o">*</span><span class="n">ifac</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="linenos" data-linenos="109 "></span>    <span class="n">res</span><span class="o">=</span><span class="n">res</span><span class="o">*</span><span class="n">tmp</span><span class="p">.</span><span class="n">inv</span><span class="p">();</span>
<span class="linenos" data-linenos="110 "></span>    <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">&lt;</span><span class="n">k</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="linenos" data-linenos="111 "></span>        <span class="n">ans</span><span class="o">+=</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="n">fac</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="n">res</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span><span class="p">;</span>
<span class="linenos" data-linenos="112 "></span>    <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%d&quot;</span><span class="p">,</span><span class="n">ans</span><span class="p">);</span>
<span class="linenos" data-linenos="113 "></span><span class="p">}</span>
</code></pre></div>
			</div>
			<div class="panel panel-default card" style="padding: 10px;height: 50px;font-size: 20px;">
				<a style="float: left;" href="\article\2021-shenxuan.html"><i class="fa fa-angle-double-left"></i></a><a style="float: right;" href="\article\2020-shenxuan.html"><i class="fa fa-angle-double-right"></i></a>
			</div>
			<div class="panel panel-default card" style="padding: 10px;font-size: 20px;" id="vcomments">
				
			</div>
			<script>
				new Valine({
					el: '#vcomments',
					appId: 'PAlFUPg0pQVTFTEo8gCB4BCf-gzGzoHsz',
					appKey: 'U38ejnLUiizJ6vLyp6ql4hRq',
					path: window.location.pathname
				})
			</script>
		</div>
		<div class="col-md-3">
				<div class="panel panel-default card">
				<div class="panel-heading">
					<h3 class="panel-title">
						<i class="fa fa-info"></i>&emsp;
						<strong>文章信息</strong>
					</h3>
				</div>
                <div style="margin: 10px;">
                    <div style="margin-top: 8px;display: flex;"> 
    <span style="flex: 1 0 auto;margin-right: 6px;">标题</span>
    <span><font style="font-weight: bold">题解 P7468 【[NOI Online 2021 提高组] 愤怒的小 N】</font></span>
	</div><div style="margin-top: 8px;display: flex;"> 
    <span style="flex: 1 0 auto;margin-right: 6px;">日期</span>
    <span>2021-04-14 12:52:23</span>
	</div>
                </div>
				</div>
				<div class="panel panel-default card">
				<div class="panel-heading">
					<h3 class="panel-title">
						<i class="fa fa-tag"></i>&emsp;
						<strong>标签</strong>
					</h3>
				</div>
				<div style="margin: 10px;">
					<a href="/tags/2021/" class="tag"><span  style="background-color: rgb(52, 152, 219);">2021</span></a>&nbsp;<a href="/tags/生成函数/" class="tag"><span  style="background-color: rgb(231, 76, 60);">生成函数</span></a>&nbsp;<a href="/tags/题解/" class="tag"><span  style="background-color: rgb(82, 196, 26);">题解</span></a>
				</div>
				</div>
				
			<div class="panel panel-default card">
					<div class="panel-heading">
						<h3 class="panel-title">
							<i class="fa fa-user-circle-o"></i>&emsp;
							<strong>caijicjl</strong>
						</h3>
					</div>
					<div style="width: 60%;display: inline-block;padding-top: 10px;">
						<ul class="propertyLinks" style="list-style-type: none;">
							<li>
								<img style="vertical-align:middle;position:relative;top:-2px" src="/img/rating-16x16.png">
								Rating:&nbsp;
								<span style="font-weight:bold;color: gray ">312</span>
							</li>
							<li>
								<img style="vertical-align:middle;position:relative;top:-2px" src="/img/star_blue_16.png">
								Contribution:&nbsp;
								<span style="color:gray;font-weight:bold;">0</span>
							</li>
						</ul>
						<ul class="nav-links">
							<li><a href="/settings/">Settings</a></li>
							<li><a href="/archives/">Blog</a></li>
							<li><a href="/teams">Teams</a></li>
							<li><a href="/submissions/dingdingsb">Submissions</a></li>
							<li><a href="/usertalk">Talks</a></li>
							<li><a href="/contests/with/dingdingsb">Contests</a></li>
						</ul>
					</div>
					<div style="display:inline-block;vertical-align: top;margin: 10px;text-align: center;">
						<div style="height:50px;width:50px"><img src="/img/avatar.png"/></div>
						<div><a href="https://www.luogu.com.cn/user/174304" style="font-weight:bold;color:gray">caijicjl</a></div>
					</div>
				</div>
		<div class="panel panel-default card">
				<div class="panel-heading">
					<h3 class="panel-title">
						<i class="fa fa-external-link"></i>&emsp;
						<strong>画中画</strong>
					</h3>
				</div>
				<div style="width:100%;margin:10px">
				<input type="text" id="url"/>
				<input value="创建" type="button" onclick="creat('kk')" /> 
				</div>
		</div>
		<script src="/js/hitokoto.js"></script>
							

				
				<span id="kk"></span>
				<div  id="myScrollspy" class="card" style="width: 100%;"  data-spy="affix">
					<script src="/js/make_toc.js"></script>
				</div>
		</div>
	</div>
 </div>
</body>
</html>
